//
//  FQAccount.m
//  WeChat
//
//  Created by 方桥 on 16/5/13.
//  Copyright © 2016年 方桥. All rights reserved.
//

#import "FQAccount.h"


#define ACUserKey @"user"
#define ACPwdKey @"pwd"
#define ACLoginKey @"login"

static NSString *domain = @"fangqiao.local";
static NSString *host = @"127.0.0.1";
static int port = 5222;

@implementation FQAccount

+(instancetype)shareAccount
{
    return [[self alloc]init];
}

+(instancetype)allocWithZone:(struct _NSZone *)zone
{
    
    static FQAccount *account;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (account == nil) {
            account = [super allocWithZone:zone];
            //从沙盒获取上次登录的信息
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            account.user = [defaults objectForKey:ACUserKey];
            account.pwd = [defaults objectForKey:ACPwdKey];
            account.login = [defaults boolForKey:ACLoginKey];
        }
    });
    return account;
}

-(void)saveToSandBox
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:self.user forKey:ACUserKey];
    [defaults setObject:self.pwd forKey:ACPwdKey];
    [defaults setBool:self.isLogin forKey:ACLoginKey];
    [defaults synchronize];
}

-(NSString *)domain
{
    return domain;
}

-(int)port
{
    return port;
}

-(NSString *)host
{
    return host;
}
@end








